﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class menu_ban : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Load_ParentProduct();
        }
    }
    protected void Load_ParentProduct()
    {
        //----hien thi danh muc cap 1----
        SqlConnection mycon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        mycon.Open();
        string sql = "select * from ProductGroup where ParentId=0"; //---menu cap 1 la menu co ParentId=0
        SqlCommand myCommand = new SqlCommand(sql, mycon);
        SqlDataAdapter myAdap = new SqlDataAdapter(myCommand);
        DataSet ds = new DataSet();
        myAdap.Fill(ds);
        rpListParentProduct.DataSource = ds.Tables[0];
        rpListParentProduct.DataBind();
        myCommand.Dispose();
        mycon.Close();
    }
    protected void rpListParentProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //---tuong ung voi mot san pham A duoc dua ra, hien thi danh sach san pham con cua A
        HiddenField hrId = (HiddenField)e.Item.FindControl("hrID"); //--- day la Id cua loai san pham A---
        Repeater rpChildrent = (Repeater)e.Item.FindControl("rpListChildProduct");
        if ((hrId != null) && (rpChildrent != null))
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            conn.Open();
            string sql = "select * from ProductGroup where ParentId=" + hrId.Value.ToString(); //---menu con cua A co ParentID la Id cua A
            //string sql = "select * from ProductGroup where ParentId=0";
            SqlCommand myCommand = new SqlCommand(sql, conn);
            SqlDataAdapter myAdap = new SqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            myAdap.Fill(ds);
            rpChildrent.DataSource = ds.Tables[0];
            rpChildrent.DataBind();
            myCommand.Dispose();
            conn.Close();
        }
    }
}
